function initPage(doctorAdviceStandingInfoJson){
	var basePath = $("#basePath").val();

	var doctorAdviceStandingRecords=doctorAdviceStandingInfoJson['doctorAdviceStandingRecords'];//长期医嘱记录集合
	for(var index in doctorAdviceStandingRecords){
		var doctorAdviceStandingRecord = doctorAdviceStandingRecords[index];
		var add_content= addDoctorAdviceRecord();
		add_content.find("input[name$='.patientName']").val(doctorAdviceStandingRecord.patientName);
		add_content.find("input[name$='.deptName']").val(doctorAdviceStandingRecord.deptName);
		add_content.find("input[name$='.bedName']").val(doctorAdviceStandingRecord.bedName);
		add_content.find("input[name$='.patientId']").val(doctorAdviceStandingRecord.patientId);
		add_content.find("input[name$='.mrId']").val(doctorAdviceStandingRecord.mrId);
		
		var doctorAdviceStandingItems = doctorAdviceStandingRecord.doctorAdviceStandingItems;
		if(doctorAdviceStandingItems.length >= 1){
			add_content.find("table[id^='doctorAdviceItems'] tbody").empty();
		}
		for(var index1 in doctorAdviceStandingItems){
			var doctorAdviceStandingItem = doctorAdviceStandingItems[index1];
			var add_item = addDoctorAdviceItem();
			add_item.find("input[name$='.doctorAdviceStartDateTime']").val(doctorAdviceStandingItem.doctorAdviceStartDateTime);
			add_item.find("input[name$='.doctorAdviceContent']").val(doctorAdviceStandingItem.doctorAdviceContent);
			add_item.find("input[name$='.doctorAdviceStartDoctorName']").val(doctorAdviceStandingItem.doctorAdviceStartDoctorName);
			add_item.find("input[name$='.doctorAdviceStartNurseName']").val(doctorAdviceStandingItem.doctorAdviceStartNurseName);
			add_item.find("input[name$='.doctorAdviceEndDateTime']").val(doctorAdviceStandingItem.doctorAdviceEndDateTime);
			add_item.find("input[name$='.doctorAdviceEndDoctorName']").val(doctorAdviceStandingItem.doctorAdviceEndDoctorName);
			add_item.find("input[name$='.doctorAdviceEndNurseName']").val(doctorAdviceStandingItem.doctorAdviceEndNurseName);
		}
		
    }
	if($("#doctor_advice_ul li").length <1){
		var add_content = addDoctorAdviceRecord();
		if(add_content.find("table[id^='doctorAdviceItems'] tbody tr").length < 1){
			addDoctorAdviceItem();
		}
	}else{
		$("#doctor_advice_ul li").first().click();
	}
}

function addDoctorAdviceRecord(){
	var doctorAdviceRecordCountOjb = $("#doctorAdviceRecordCount");
	var count = parseInt(doctorAdviceRecordCountOjb.val());
	var addli=$("#template_doctor_advice_ul li:eq(0)").clone();
    addli.text("记录"+(count+1));
    addli.attr("data-index",count);
    $("#doctor_advice_ul").append(addli);
    addli.addClass("selected").siblings().removeClass("selected");
    addli.click(function(){
    	$(this).addClass("selected").siblings().removeClass("selected");
        $("#doctorAdviceRecord"+$(this).attr("data-index")).show().siblings().hide();
    });
   
	var add_content=$("#templateDoctorAdviceRecord").clone();
	add_content.attr("id","doctorAdviceRecord"+count);
	add_content.find("#doctorAdviceItems").attr("id","doctorAdviceItems"+count);
	add_content.find("#doctorAdviceItemCount").attr("id","doctorAdviceItemCount"+count);
////	
	add_content.find("input[name^='doctorAdviceStandingRecords[0].']").each(function(){
		var eventObj = $(this);
		eventObj.attr("name",eventObj.attr("name").replace("doctorAdviceStandingRecords[0]", "doctorAdviceStandingRecords["+count+"]"));
   		
	});
	$("#doctorAdviceRecords").append(add_content);

	add_content.show().siblings().hide();
	doctorAdviceRecordCountOjb.val(count +1);
	return add_content;
}

function addDoctorAdviceItem(){
	var basePath = $("#basePath").val();
	
	var add_content=$("#templateDoctorAdviceItemTr").clone();
	add_content.removeAttr("id");
	
	
	var index = $("#doctor_advice_ul li[class='selected']").attr("data-index");
	var doctorAdviceItemCountOjb = $("#doctorAdviceItemCount"+index);
	var count = parseInt(doctorAdviceItemCountOjb.val());
	add_content.find("input[name^='doctorAdviceStandingRecords[0].doctorAdviceStandingItems[0].']").each(function(){
		var eventObj = $(this);
		eventObj.attr("name",eventObj.attr("name").replace("doctorAdviceStandingRecords[0].doctorAdviceStandingItems[0]", "doctorAdviceStandingRecords["+index+"].doctorAdviceStandingItems["+count+"]"));
   		
	});
	
	
	$("#doctorAdviceItems"+index+" tbody").append(add_content);
	doctorAdviceItemCountOjb.val(count +1);
	return add_content;
}

function deleteDoctorAdviceItem(obj){
	$(obj).parent().parent().remove();
}

function deleteDoctorAdviceRecord(){
	var delete_option = $("#doctor_advice_ul li[class='selected']");
	var delete_index = delete_option.attr("data-index");
	delete_option.remove();
	
    $("#doctor_advice_ul li:last").addClass("selected").siblings().removeClass("selected");
    /*内容删除最后一项*/
    $("#doctorAdviceRecord"+delete_index).remove();
    $("#doctorAdviceRecords>div:last").show().siblings().hide();
}